package com.wei.shopping.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wei.shopping.dao.NewsMapper;
import com.wei.shopping.entrty.PageResult;
import com.wei.shopping.entrty.QueryPageBean;
import com.wei.shopping.pojo.News;
import com.wei.shopping.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class NewsServiceImpl implements NewsService {
    @Resource
    private NewsMapper newsMapper;
    /**
     * 添加公告
     * @param news
     */
    public void add(News news){
        newsMapper.add(news);
    }
    /**
     * 查找全部的公告
     * @return
     */
    public PageResult findall(QueryPageBean queryPageBean){
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<News> findall = newsMapper.findall(queryPageBean.getQueryString());
        return new PageResult(findall.getTotal(),findall.getResult());
    }

    /**
     * 根据id查询news
     * @param id
     * @return
     */
    public News findById(String id){
        News byId = newsMapper.findById(id);
        return byId;
    }

    /**
     * 浏览量+1
     * @param id
     */
    public void addNewsRednumber(String id){
        newsMapper.addNewsRednumber(id);
    }

    /**
     * 更新数据
     * @param news
     */
    public void update(News news){
        newsMapper.update(news);
    }
    /**
     * 删除新闻
     * @param id
     */
    public void delete(String id){
        newsMapper.delete(id);
    }
}
